package cn.com.zpark.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.session
 * @ClassName: SessionDemo3
 * @Description:
 * @author: RZS
 * @date: 2021/11/15  15:46
 */
@WebServlet("/sd3.do")
public class SessionDemo3 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 设置session失效时间
         */
        // 获取session对象
        HttpSession session = request.getSession();

        // 设置session失效时间
        session.setMaxInactiveInterval(60);

        System.out.println(session.getId());
        System.out.println("******************");

        // 获取cookie
        Cookie[] cookies = request.getCookies();
        if(cookies != null){
            for (Cookie cookie : cookies) {
                System.out.println(cookie.getName()+"： "+cookie.getValue());
            }
        }
    }
}
